package com.example.demo1.util;

import java.sql.*;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author jyangzi5
 * @version 1.0
 * @description: TODO
 * @date 2021/4/19 14:06
 */
public class Test {

    public static void main(String[] args) throws Exception {
        insert ();
    }


    public static void insert () throws Exception {


        String driverName = "com.mysql.cj.jdbc.Driver";
        String url ="jdbc:mysql://192.168.65.16:4000/test";
        String password = "";
        String user ="root";
        Class.forName(driverName);
        Connection con = DriverManager.getConnection(url,user,password);
        con.setAutoCommit(false);
        String sql ="INSERT INTO test.company (id, name, area, address, phone, location, leader, open_time, owner, owner_phone, remark, sort) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?);";
        PreparedStatement ps = con.prepareStatement(sql);
        for (long i = 500000; i <1000000 ; i++) {
            System.out.println("------"+i);
            ps.setLong(1,i);
            ps.setString(2,"小武"+i);
            ps.setString(3,"小武武"+i);
            ps.setString(4,"小武武武"+i);
            ps.setString(5,"小武武武"+i);
            ps.setString(6,"小武武武武"+i);
            ps.setString(7,"小武武武武武"+i);
            ps.setString(8,"小武武武武武武"+i);
            ps.setString(9,"小武武武武武武武"+i);
            ps.setString(10,"小武武武武武武武"+i);
            ps.setString(11,"小武武武武武武武武"+i);
            ps.setString(12,""+i);
            ps.addBatch();
            if(i%5000==0){
                ps.executeBatch();
                con.commit();
                con.setAutoCommit(false);
            }
        }

        con.commit();
        if(ps!=null){
            ps.close();
        }

        if(con!=null){
            con.close();
        }


    }
}
